﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace Web
{
    public partial class lien_he : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                
            }
        }

        protected void ButtonGui_Click(object sender, EventArgs e)
        {
            LabelThongBaoLienHe.Text = "";
            if (TextBoxTenCongTy_NLH.Text == "" || TextBoxHoTen_NLH.Text == "" || TextBoxDiaChi_NLH.Text == "" || TextBoxSDT_NLH.Text == "" || TextBoxEmail_NLH.Text == "" || TextBoxNoiDung_NLH.Text == "")
            {
                LabelThongBaoLienHe.Text = "Xin nhập đầy đủ dữ liệu!";
            }
            else
            {
                LabelThongBaoLienHe.Text = "Bạn đã liên hệ thành công";

                string connectionstring = ConfigurationManager.ConnectionStrings["cnn"].ConnectionString;
                SqlConnection conn = new SqlConnection(connectionstring);
                string sql = "insert into LienHe(TenCongTy_NLH, HoTen_NLH, DiaChi_NLH, SDT_NLH, Email_NLH, NoiDung_NLH) values (@tencongtynlh, @hotennlh, @diachi, @sdt, @email, @nd)";
                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@tencongtynlh", TextBoxTenCongTy_NLH.Text);
                cmd.Parameters.AddWithValue("@hotennlh", TextBoxHoTen_NLH.Text);
                cmd.Parameters.AddWithValue("@diachi", TextBoxDiaChi_NLH.Text);
                cmd.Parameters.AddWithValue("@sdt", TextBoxSDT_NLH.Text);
                cmd.Parameters.AddWithValue("@email", TextBoxEmail_NLH.Text);
                cmd.Parameters.AddWithValue("@nd", TextBoxNoiDung_NLH.Text);

                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
            }  
        } 
    }
}